/*
 * @Descripttion:
 * @TapdLink: https://XXX
 * @DesignsLink: https://XXX
 * @RelatedPersons: XXX[市场]、XXX[产品]、XXX[前端]、XXX[后端]、XXX[设计]
 * @version: 1.0.0
 * @Author: Shentong
 * @LastEditors: shentong
 * @Date: 2021-09-24 11:32:10
 */
import { server } from './server'

interface IauthorRequst {
  encryptedData: string
  iv: string
  code: string
}
// 登录授权
export const authorization = (params: IauthorRequst) => {
  const { encryptedData, iv, code } = params
  return server.POST<IauthorRequst, any>(`/user/wx/phone`, params)

  // return server.POST<IauthorRequst, any>(`/user/wx/phone?encryptedData=${encryptedData}&iv=${iv}&code=${code}`)
}
interface IsaveCommentRequst {
  shopId: string | number // 商铺id
  orderId: string | number // 订单id
  totalGrade: string | number // 总评分
  tasteGrade: string | number // 味道评分
  packGrade: string | number // 包装评分
  content: string | number // 评价内容
  isAnonymity: string | number // 是否匿名,0:否;1:是
}
// 用户评价-保存评价
export const saveComment = (params: IsaveCommentRequst) => {
  const {
    shopId,
    orderId,
    totalGrade,
    tasteGrade,
    packGrade,
    content,
    isAnonymity = 1
  } = params
  return server.POST<IauthorRequst, any>(
    `/user/evaluate/add/save?shopId=${shopId}&content=${content}&isAnonymity=${isAnonymity}&orderId=${orderId}&packGrade=${packGrade}&totalGrade=${totalGrade}&totalGrade=${totalGrade}&tasteGrade=${tasteGrade}`
  )
}
interface IaddressPageRequst {
  pageNo: string | number
  pageSize: string | number
}
// 收货地址列表
export const getAddressPage = (params: IaddressPageRequst) => {
  const { pageNo, pageSize } = params
  return server.POST<IaddressPageRequst, any>(
    `/user/address/page?pageNo=${pageNo}&pageSize=${pageSize}`
  )
}
export interface IsaveAddressRequst {
  userName: string
  gender: number | string
  cellPhone: string
  address: string
  lon: string
  lat: string
  detailAdd: string
  addressId?: string
  deliveryFloor?: string | number
}
interface IdelAddressRequst {
  addressId: string
}
// 保存收货地址
export const saveAddress = (params: IsaveAddressRequst) => {
  const { userName, gender, cellPhone, address, lon, lat, detailAdd, deliveryFloor } = params
  return server.POST<IsaveAddressRequst, any>(
    `/user/address/wx/add/save?userName=${userName}&deliveryFloor=${deliveryFloor}&gender=${gender}&cellPhone=${cellPhone}&address=${address}&lon=${lon}&lat=${lat}&detailAdd=${detailAdd}`
  )
}
// 编辑-保存收货地址
export const saveEditAddress = (params: IsaveAddressRequst) => {
  const {
    userName,
    gender,
    cellPhone,
    address,
    lon,
    lat,
    detailAdd,
    addressId,
    deliveryFloor
  } = params
  return server.POST<IsaveAddressRequst, any>(
    `/user/address/wx/edit/save?userName=${userName}&deliveryFloor=${deliveryFloor}&addressId=${addressId}&gender=${gender}&cellPhone=${cellPhone}&address=${address}&lon=${lon}&lat=${lat}&detailAdd=${detailAdd}`
  )
}
// 删除地址
export const delAddress = (params: IdelAddressRequst) => {
  return server.POST<IdelAddressRequst, any>(
    `/user/address/delete?addressId=${params.addressId}`
  )
}

// 是否收藏
export const getIsCollect = params => {
  const { shopId } = params
  return server.POST<any, any>(`/user/collect/isCollect?shopId=${shopId}`)
}

// 添加收藏
export const addCollect = params => {
  const { shopId } = params
  return server.POST<any, any>(`/user/collect/add?shopId=${shopId}`)
}

// 取消收藏
export const cancelCollect = params => {
  const { shopId } = params
  return server.POST<any, any>(`/user/collect/cancel?shopId=${shopId}`)
}

// 获取楼层
export const getFloor = () => {
  return server.POST<IdelAddressRequst, any>(
    `/user/address/delivery/floor`
  )
}
